COLEBROOK

Overview

The COLEBROOK function calculates the Darcy friction factor for turbulent flow in pipes using the Colebrook equation, a fundamental correlation in fluid mechanics for determining pressure drop due to friction. This function provides three solution methods: an exact analytical solution using the Lambert W function (default), a high-precision mpmath solution, or a numerical iterative solution.

The Colebrook equation was originally published in 1939 by C.F. Colebrook and is widely considered the most accurate implicit correlation for turbulent pipe friction. The equation relates the friction factor to both the Reynolds number and the relative roughness of the pipe wall:

\frac{1}{\sqrt{f}} = -2\log_{10}\left(\frac{\epsilon/D}{3.7} + \frac{2.51}{Re\sqrt{f}}\right)

where f is the Darcy friction factor, \epsilon/D is the relative roughness (absolute roughness divided by pipe diameter), and Re is the Reynolds number.

This implementation uses the fluids library, a Python package for fluid dynamics and engineering thermodynamics calculations. The analytical solution is derived using a computer algebra system (CAS) and expressed in terms of the Lambert W function:

f_d = \frac{\ln(10)^2 \cdot 3.7^2 \cdot 2.51^2}{\left(\ln(10)\epsilon/D \cdot Re - 2 \cdot 2.51 \cdot 3.7 \cdot \text{lambertW}\left[\frac{\ln(10)}{10^{(\epsilon Re)/(2.51 \cdot 3.7 D)}} \cdot \frac{Re^2}{2.51^2}\right]\right)^2}

For more details, see the Colebrook function documentation and the friction factor overview.

This example function is provided as-is without any representation of accuracy.

Excel Usage

=COLEBROOK(Re, eD, tol)
  • Re (float, required): Reynolds number, [-]
  • eD (float, required): Relative roughness (roughness/diameter), [-]
  • tol (float, optional, default: null): Solution tolerance. None = analytical (default), 0 = mpmath exact, user value = numerical solution, [-]

Returns (float): Darcy friction factor, [-], or error message (str) if input is invalid.

Examples

Example 1: Standard turbulent flow case

Inputs:

Re eD
100000 0.0001

Excel formula:

=COLEBROOK(100000, 0.0001)

Expected output:

0.0185

Example 2: Smooth pipe (very low roughness)

Inputs:

Re eD
100000 0.000001

Excel formula:

=COLEBROOK(100000, 0.000001)

Expected output:

0.018

Example 3: Rough pipe (higher roughness)

Inputs:

Re eD
100000 0.01

Excel formula:

=COLEBROOK(100000, 0.01)

Expected output:

0.0385

Example 4: High Reynolds number flow

Inputs:

Re eD
1000000 0.0001

Excel formula:

=COLEBROOK(1000000, 0.0001)

Expected output:

0.0134

Example 5: Numerical solution with tolerance

Inputs:

Re eD tol
100000 0.0001 0.0001

Excel formula:

=COLEBROOK(100000, 0.0001, 0.0001)

Expected output:

0.0185

Python Code

import micropip
await micropip.install(["fluids"])
from fluids.friction import Colebrook as fluids_colebrook

def colebrook(Re, eD, tol=None):
    """
    Calculate Darcy friction factor using exact solution to the Colebrook equation.

    See: https://fluids.readthedocs.io/fluids.friction.html#fluids.friction.Colebrook

    This example function is provided as-is without any representation of accuracy.

    Args:
        Re (float): Reynolds number, [-]
        eD (float): Relative roughness (roughness/diameter), [-]
        tol (float, optional): Solution tolerance. None = analytical (default), 0 = mpmath exact, user value = numerical solution, [-] Default is None.

    Returns:
        float: Darcy friction factor, [-], or error message (str) if input is invalid.
    """
    # Validate and convert Re
    try:
        Re = float(Re)
    except (ValueError, TypeError):
        return "Error: Re must be a number."

    # Validate and convert eD
    try:
        eD = float(eD)
    except (ValueError, TypeError):
        return "Error: eD must be a number."

    # Validate and convert tol if provided
    if tol is not None:
        try:
            tol = float(tol)
        except (ValueError, TypeError):
            return "Error: tol must be a number or None."

    # Validation: Re must be positive
    if Re <= 0:
        return "Error: Reynolds number must be positive."

    # Validation: eD must be non-negative
    if eD < 0:
        return "Error: Relative roughness must be non-negative."

    try:
        result = fluids_colebrook(Re=Re, eD=eD, tol=tol)

        # Handle NaN and infinity values
        if result != result:  # NaN check
            return "nan"
        if result == float('inf'):
            return "inf"
        if result == float('-inf'):
            return "-inf"

        return float(result)
    except OverflowError:
        return "Error: Overflow in calculation. Try using numerical solution with tol parameter."
    except Exception as e:
        return f"Error computing Colebrook friction factor: {str(e)}"

Online Calculator